﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookStore
{
    public partial class ChiTiet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request.QueryString["bookid"]);
            Basket gio = (Basket)Session["GioHang"];
            int soluong = 0;
            if(TextBox1.Text != "")
                soluong = Convert.ToInt32(TextBox1.Text);
            else
                soluong = 1;

            using (BookStoreEntities context = new BookStoreEntities())
            {
                Sach s = (from x in context.Saches
                          where x.MaSach == id
                          select x).FirstOrDefault();
            if (gio != null)
            {
                gio.Add(s.MaSach.ToString(), s.TenSach, DateTime.Now, "", s.ImageURL , s.ChieuCao,
                    s.ChieuRong,
                    s.BeDay,
                    s.KhoiLuong, soluong, (long)s.DonGia);
            }
            else
            {
                Session["GioHang"] = new Basket();
            }
            Response.Write("<div class='added-item-alert'>" + s.TenSach + " have added to your ShoppingCart</div>");
            }
        }

    }
}